# -*- coding : utf-8 -*-
import os
from config import cfg

def record_result(string):
    print(string)
    file_path = "result\\" + cfg.net + "_" + str(cfg.learning_rate) + ".txt"
    py_file_path = 'config.py'

    # 判断文件是否存在
    if os.path.isfile(file_path):
        # 如果文件存在，追加字符串
        with open(file_path, 'a') as f:
            f.write(string + '\n')
    else:
        # 如果文件不存在，创建文件并将.py文件的内容写入到文本文件
        if os.path.isfile(py_file_path):
            with open(py_file_path, 'r',encoding='utf-8', errors='ignore') as py_file:
                py_content = py_file.read()
            with open(file_path, 'w') as f:
                f.write(py_content)
        else:
            print('Error: 无法找到.py文件')
